﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using XiuxianGame.DBOper;
using XiuxianGame.人物;
using XiuxianGame.运行时资源;
using XiuxianGame.运行时资源.事件方法;

namespace XiuxianGame
{
    public partial class MainPage : Form
    {
        public MainPage()
        {
            InitializeComponent();

        }

        // 静态变量 实时使用
        static DBConnection conn;
        static Player player = new Player();
        static CurMap map = new CurMap();

        //信息面板
        XiuxianGame.图形资源库.信息显示栏.人物属性 pinfo = new XiuxianGame.图形资源库.信息显示栏.人物属性();
        XiuxianGame.图形资源库.信息显示栏.背包 binfo = new XiuxianGame.图形资源库.信息显示栏.背包();
        XiuxianGame.图形资源库.信息显示栏.修行页面 xinfo = new XiuxianGame.图形资源库.信息显示栏.修行页面();

        public static DBConnection Conn { get => conn; set => conn = value; }
        public static Player Player { get => player; set => player = value; }
        internal static CurMap Map { get => map; set => map = value; }

        private void MainPage_Load(object sender, EventArgs e)
        {

            //加载数据库连接
            DBConnection.conninit("D:\\vsproject\\XiuxianGame\\DataBase\\XiuxianDB.xlsx");

            //启动时钟
            timer1.Enabled = true;

        }

        private void MainPage_Shown(object sender, EventArgs e)
        {

            // 载入地图 
            // DEBUG时 D:\vsproject\XiuxianGame\XiuxianGame\bin\Debug\netcoreapp3.1\'.”
            Map.initmap(ItemOper.getPlayMapFile());
            this.mapControl.set(Map.Map, new Point(5, 4));

            //载入玩家
            Player = Player.load();
            //载入NPC（当前地图）
            当前地点信息1.loadThisNPC();


            //下方状态栏
            progressColorBar1.Fcolor = Color.Red;
            progressColorBar2.Fcolor = Color.Blue;
            progressColorBar3.Fcolor = Color.Green;

            progressColorBar1.Maximum = Player.Maxhp;
            progressColorBar2.Maximum = Player.Maxmp;
            progressColorBar3.Maximum = Player.Maxtp;

            progressColorBar1.Value = Player.Hp;
            this.progressColorBar1.DataBindings.Add(new System.Windows.Forms.Binding("Value", Player.Dt, "hp", true));

            progressColorBar2.Value = Player.Mp;
            progressColorBar3.Value = Player.Tp;

        }

        private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
        {

        }

        private void 人物属性ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            //清理Panel内容ToolStripMenuItem_Click(sender,e);
            pinfo.load(Player);
            this.infopanel.Controls.Add(pinfo);
            pinfo.BringToFront();

        }

        private void 清理Panel内容ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            while(infopanel.Controls.Count > 0) { infopanel.Controls.RemoveAt(infopanel.Controls.Count - 1); }
        }

        

        private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void infopanel_ControlRemoved(object sender, ControlEventArgs e)
        {

        }

        private void MainPage_FormClosed(object sender, FormClosedEventArgs e)
        {
            DBConnection.close();
        }

        private void 包裹ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //清理Panel内容ToolStripMenuItem_Click(sender,e);
           
            binfo.setData(new ItemOper().getPlayerPackage(Player.Id));
            binfo.Refresh();
            this.infopanel.Controls.Add(binfo);
            binfo.BringToFront();
        }

        private void 修行ToolStripMenuItem_Click(object sender, EventArgs e)
        {
           
            xinfo.setExp(Player.Jingyan,new XiuxingOper().getNeexExp(Player.Djingjie,Player.Xjingjie));
            xinfo.Refresh();
            this.infopanel.Controls.Add(xinfo);
            xinfo.BringToFront();
        }

        private void time_process_Exited(object sender, EventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            //时钟
            label_time.Text = DateTime.Now.ToLocalTime().ToString();
        }

        private void infpRichText_Click(object sender, EventArgs e)
        {
            this.当前地点信息1.BringToFront();
        }

    }
}
